package com.smart.fourteen.mybatis.sessionfactory;

import com.smart.fourteen.mybatis.model.Topic;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author junrui.wang
 * @create 2019/11/13
 */
public class Test {
    public static void main(String[] args) {
        ApplicationContext ac = new ClassPathXmlApplicationContext("com/smart/fourteen/mybatis/sessionfactory/applicationContext-mybatis.xml");
        SqlSessionFactory sessionFactory = (SqlSessionFactory) ac.getBean("sessionFactory");
        SqlSession session = sessionFactory.openSession();
        Topic topic = session.selectOne("com.smart.fourteen.mybatis.dao.TopicDao.getTopic", 1);
        System.out.println(topic);

        Topic topic1 = new Topic();
        topic1.setName("5");
        session.insert("com.smart.fourteen.mybatis.dao.TopicDao.addTopic", topic1);

        topic.setName("1");
        session.update("com.smart.fourteen.mybatis.dao.TopicDao.updateTopic", topic);

    }
}
